package zdream.pmfield.stage.effect;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

import static zdream.pmfield.data.foe.MoveAdditionalEffects.*;

/**
 * @author Zdream
 * @date 2023-11-17
 * @since 0.0.1
 */
public class Effects {
	private final Map<String, Function<EffectDescription, AbstractEffect>> effectFactories = new HashMap<>();

	{
		effectFactories.put(E_DELAY, (desc) -> new DelayEffect());
		effectFactories.put(E_FIXED, TypeFixedRateEffect::new);
		effectFactories.put(E_FIXED_BUFF, BuffFixedRateEffect::new);
		effectFactories.put(E_REMOVE_BUFF, RemoveBuffEffect::new);
		effectFactories.put(E_MOVE_TO, (desc) -> new MoveToEffect());
		effectFactories.put(E_APPLY_BUFF, ApplyBuffEffect::new);
		effectFactories.put(E_BSTAT_CHANGE, BStatChangeEffect::new);
		effectFactories.put(E_BSTAT_SET, BStatChangeEffect::new);
		effectFactories.put(E_CHARGING, ChargingEffect::new);
	}

	public AbstractEffect createEffect(String effectText) {
		return createEffect(EffectDescription.of(effectText));
	}

	public AbstractEffect createEffect(EffectDescription description) {
		Function<EffectDescription, AbstractEffect> factory = effectFactories.get(description.category);
		return Objects.requireNonNull(factory).apply(description);
	}
}
